$(function() {	
	$(document).ajaxSend(function(e,xhr,opt){
		$("<div id='loadingbackground" + opt.url.length + "'>" 
				+"<div id='loadWindowId' style='display:block;'>"
		 		+"<div style='margin-top:18%;font-size:25px;font-weight:bold;'><center>执行中，请等待...</center></div>"
		 		+"<div style='margin-top:0.8%;'>"
		 		+"<center><img style='display:block' src='/crm/css/skin/images/common/loading.gif'></center>"
		 		+"</div>"
	 			+"</div>"
				+"</div>"
				).css({
			position:'absolute',
			top:0,
			left:0,
			backgroundColor:"#FCFCFC",
			opacity:0.5,
			zIndex:110010
		})
		.height($(document).height())
		.width($(document).width()).hide().appendTo("body");
		$("#loadingbackground" + opt.url.length).show();
	});
	$(document).ajaxComplete(function(e,xhr,opt){
	 	$("#loadingbackground" + opt.url.length).remove();
	});
	$.ajaxSetup({
	    type: 'POST',
	    complete: function(xhr,status) {
	        var sessionStatus = xhr.getResponseHeader('sessionstatus');
	        if(sessionStatus == 'timeout') {
	            var top = getTopWinow();
	            $.messager.confirm('提示', '由于您长时间没有操作, 登录已失效, 请重新登录.', function(r){
	            	if(r){
	            		if(IsPC() ) {
	            			top.location.href = '/SalesSystem/jsp/login.jsp';            
	            		} else {
	            			//top.location.href = '/SalesSystem/mobilehtml/login.html';            
	            			top.location.href = '/SalesSystem/mobilejsp/login.jsp';            
	            		}
	            	}
	            });
	        }
	    }
	});
	function getTopWinow(){
	    var p = window;
	    while(p != p.parent){
	        p = p.parent;
	    }
	    return p;
	}
	//判断是手机还是pc
	function IsPC() {
	    var userAgentInfo = navigator.userAgent;
	    var Agents = ["Android", "iPhone",
	                "SymbianOS", "Windows Phone",
	                "iPad", "iPod"];
	    var flag = true;
	    for (var v = 0; v < Agents.length; v++) {
	        if (userAgentInfo.indexOf(Agents[v]) > 0) {
	            flag = false;
	            break;
	        }
	    }
	    return flag;
	}
});


	